package top.malaoshi.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import top.malaoshi.entity.Notice;
import top.malaoshi.model.JsonResult;
import top.malaoshi.service.NoticeServiceImpl;

import javax.annotation.Resource;
import java.util.Date;

@RestController
public class NoticeCtrl {
    Logger log= LoggerFactory.getLogger(NoticeCtrl.class);
    @Resource
    private NoticeServiceImpl noticeService;

    @GetMapping(value="/getNoticeById/{id}")
    public JsonResult<Notice> getNoticeById(@PathVariable("id") String id){
        String content=String.format("=====id:%s--%s", id,new Date());
        log.info(content);

        Notice notice=noticeService.getNoticeById(id);
        JsonResult<Notice> res=new JsonResult<>(200,"成功！");
        res.setData(notice);
        return res;
    }
    //url后面没有/，client发请求时有没有/都可以。如果这里有/，那么client发请求时必须带上/
    @PostMapping(value="/sendNotice")
    //ums服务调用该接口，传递的数据是json格式，所以此处要用@RequestBody注解
    public JsonResult<Notice> sendNotice(@RequestBody Notice notice){
        noticeService.sendNotice(notice);
        return new JsonResult<>(200,"成功！");
    }
}
